use master
go
CREATE DATABASE [Chili]
GO
USE [Chili]
GO
CREATE LOGIN [delivery] WITH PASSWORD = 'P@$$w0rd';
GO
CREATE USER [delivery] FOR LOGIN [delivery] WITH DEFAULT_SCHEMA=[delivery]
GO
CREATE SCHEMA [delivery] AUTHORIZATION [delivery]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [delivery].[tb_departamento](
	[idDepartamento] [int] NOT NULL,
	[descripcion] [nvarchar](100) NULL,
 CONSTRAINT [PK_tb_departamento] PRIMARY KEY CLUSTERED 
(
	[idDepartamento] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [delivery].[tb_cliente]    Script Date: 07/02/2013 23:53:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [delivery].[tb_cliente](
	[idCliente] [int] IDENTITY(1,1) NOT NULL,
	[nombres] [nvarchar](100) NULL,
	[apellidoPaterno] [nvarchar](100) NULL,
	[apellidoMaterno] [nvarchar](100) NULL,
	[idTipoDocumentoIdentidad] [int] NULL,
	[numeroDocumentoIdentidad] [nvarchar](50) NULL,
	[direccion] [nvarchar](150) NULL,
 CONSTRAINT [pk_tb_cliente] PRIMARY KEY CLUSTERED 
(
	[idCliente] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [delivery].[tb_hoja_ruta]    Script Date: 07/02/2013 23:53:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [delivery].[tb_hoja_ruta](
	[idHojaRuta] [int] IDENTITY(1,1) NOT NULL,
       [idZonaReparto] [int] NULL,
       [idRepartidor] [int] NULL
 CONSTRAINT [PK_tb_hoja_ruta] PRIMARY KEY CLUSTERED 
(
	[idHojaRuta] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [delivery].[tb_producto]    Script Date: 07/02/2013 23:53:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [delivery].[tb_producto](
	[idProducto] [int] IDENTITY(1,1) NOT NULL,
	[descripcion] [nvarchar](100) NULL,
	[precioUnitario] [decimal](10, 2) NULL,
 CONSTRAINT [pk_tb_producto] PRIMARY KEY CLUSTERED 
(
	[idProducto] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [delivery].[tb_repartidor]    Script Date: 07/02/2013 23:53:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [delivery].[tb_repartidor](
	[idRepartidor] [int] NOT NULL,
	[nombres] [nvarchar](100) NULL,
	[apellidoPaterno] [nvarchar](100) NULL,
	[apellidoMaterno] [nvarchar](100) NULL,
	[idTipoDocumentoIdentidad] [int] NULL,
	[numeroDocumentoIdentidad] [nvarchar](50) NULL,
 CONSTRAINT [PK_tb_repartidor] PRIMARY KEY CLUSTERED 
(
	[idRepartidor] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [delivery].[tb_parametros]    Script Date: 07/02/2013 23:53:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [delivery].[tb_parametros](
	[idParametro] [int] IDENTITY(1,1) NOT NULL,
	[codigo] [int] NULL,
	[tipo] [nvarchar](50) NULL,
	[valor] [nvarchar](50) NULL,
	[descripcion] [nvarchar](50) NULL,
 CONSTRAINT [pk_tb_parametros] PRIMARY KEY CLUSTERED 
(
	[idParametro] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [delivery].[tb_zona_reparto]    Script Date: 07/02/2013 23:53:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [delivery].[tb_zona_reparto](
	[idZonaReparto] [int] IDENTITY(1,1) NOT NULL,
	[descripcion] [nvarchar](100) NULL,
 CONSTRAINT [PK_tb_zona_reparto] PRIMARY KEY CLUSTERED 
(
	[idZonaReparto] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [delivery].[tb_vehiculo]    Script Date: 07/02/2013 23:53:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [delivery].[tb_vehiculo](
	[idVehiculo] [int] IDENTITY(1,1) NOT NULL,
	[placa] [nvarchar](100) NOT NULL,
	[anio] [int] NULL,
	[estado] [nvarchar](100) NULL,
	[idRepartidor] [int] NULL,
 CONSTRAINT [PK_tb_vehiculo] PRIMARY KEY CLUSTERED 
(
	[idVehiculo] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [delivery].[tb_provincia]    Script Date: 07/02/2013 23:53:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [delivery].[tb_provincia](
	[idProvincia] [int] IDENTITY(1,1) NOT NULL,
	[idDepartamento] [int] NOT NULL,
	[descripcion] [nvarchar](100) NULL,
 CONSTRAINT [PK_tb_provincia] PRIMARY KEY CLUSTERED 
(
	[idProvincia] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [delivery].[tb_pedido]    Script Date: 07/02/2013 23:53:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [delivery].[tb_pedido](
	[idPedido] [int] IDENTITY(1,1) NOT NULL,
	[fechaRegistro] [date] NULL,
	[subTotal] [decimal](10, 2) NULL,
	[igv] [decimal](10, 2) NULL,
	[total] [decimal](10, 2) NULL,
	[idCliente] [int] NOT NULL,
	[codigoMedioPago] [int] NOT NULL,
	[direccionEntrega] [nvarchar](150) NOT NULL,
	[telefonoEntrega] [nvarchar](15) NOT NULL,
	[observaciones] [nvarchar](300) NOT NULL,
	[estado] [nvarchar](100) NULL,
	[idHojaRuta] [int] NULL,
 CONSTRAINT [pk_tb_pedido] PRIMARY KEY CLUSTERED 
(
	[idPedido] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [delivery].[tb_distrito]    Script Date: 07/02/2013 23:53:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [delivery].[tb_distrito](
	[idDistrito] [int] IDENTITY(1,1) NOT NULL,
	[idProvincia] [int] NOT NULL,
	[idDepartamento] [int] NOT NULL,
	[idZonaReparto] [int] NOT NULL,
	[descripcion] [nvarchar](100) NULL,
 CONSTRAINT [PK_tb_distrito] PRIMARY KEY CLUSTERED 
(
	[idDistrito] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [delivery].[tb_detalle_pedido]    Script Date: 07/02/2013 23:53:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [delivery].[tb_detalle_pedido](
	[idPedido] [int] NOT NULL,
	[idProducto] [int] NOT NULL,
	[cantidad] [int] NULL,
	[precioUnitario] [decimal](10, 2) NULL,
 CONSTRAINT [pk_tb_detalle_pedido] PRIMARY KEY CLUSTERED 
(
	[idPedido] ASC,
	[idProducto] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [delivery].[tb_inspeccion_vehicular]    Script Date: 07/02/2013 23:53:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [delivery].[tb_inspeccion_vehicular](
	[idInspeccionVehicular] [int] NOT NULL,
	[idVehiculo] [int] NOT NULL,
	[turno] [nvarchar](50) NOT NULL,
	[kmInicial] [decimal](10, 2) NOT NULL,
	[kmFinal] [decimal](10, 2) NOT NULL,
	[averias] [nvarchar](500) NOT NULL,
	[estado] [nvarchar](100) NOT NULL,
 CONSTRAINT [PK_tb_inspeccion_vehicular] PRIMARY KEY CLUSTERED 
(
	[idInspeccionVehicular] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [delivery].[tb_incidencia]    Script Date: 07/02/2013 23:53:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [delivery].[tb_incidencia](
	[idIncidencia] [int] IDENTITY(1,1) NOT NULL,
	[descripcion] [nvarchar](100) NULL,
	[fechaRegistro] [datetime] NULL,
	[idPedido] [int] NOT NULL,
 CONSTRAINT [PK_tb_incidencia] PRIMARY KEY CLUSTERED 
(
	[idIncidencia] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  ForeignKey [FK_tb_vehiculo_tb_repartidor]    Script Date: 07/02/2013 23:53:32 ******/
ALTER TABLE [delivery].[tb_vehiculo]  WITH CHECK ADD  CONSTRAINT [FK_tb_vehiculo_tb_repartidor] FOREIGN KEY([idRepartidor])
REFERENCES [delivery].[tb_repartidor] ([idRepartidor])
GO
ALTER TABLE [delivery].[tb_vehiculo] CHECK CONSTRAINT [FK_tb_vehiculo_tb_repartidor]
GO

ALTER TABLE [delivery].[tb_hoja_ruta]  WITH CHECK ADD  CONSTRAINT [FK_tb_hoja_ruta_tb_repartidor] FOREIGN KEY([idRepartidor])
REFERENCES [delivery].[tb_repartidor] ([idRepartidor])
GO
ALTER TABLE [delivery].[tb_hoja_ruta] CHECK CONSTRAINT [FK_tb_hoja_ruta_tb_repartidor]
GO

/****** Object:  ForeignKey [FK_tb_provincia_tb_departamento]    Script Date: 07/02/2013 23:53:32 ******/
ALTER TABLE [delivery].[tb_provincia]  WITH CHECK ADD  CONSTRAINT [FK_tb_provincia_tb_departamento] FOREIGN KEY([idDepartamento])
REFERENCES [delivery].[tb_departamento] ([idDepartamento])
GO
ALTER TABLE [delivery].[tb_provincia] CHECK CONSTRAINT [FK_tb_provincia_tb_departamento]
GO
/****** Object:  ForeignKey [FK_tb_pedido_tb_cliente]    Script Date: 07/02/2013 23:53:32 ******/
ALTER TABLE [delivery].[tb_pedido]  WITH CHECK ADD  CONSTRAINT [FK_tb_pedido_tb_cliente] FOREIGN KEY([idCliente])
REFERENCES [delivery].[tb_cliente] ([idCliente])
GO
ALTER TABLE [delivery].[tb_pedido] CHECK CONSTRAINT [FK_tb_pedido_tb_cliente]
GO
/****** Object:  ForeignKey [FK_tb_pedido_tb_hoja_ruta]    Script Date: 07/02/2013 23:53:32 ******/
ALTER TABLE [delivery].[tb_pedido]  WITH CHECK ADD  CONSTRAINT [FK_tb_pedido_tb_hoja_ruta] FOREIGN KEY([idHojaRuta])
REFERENCES [delivery].[tb_hoja_ruta] ([idHojaRuta])
GO
ALTER TABLE [delivery].[tb_pedido] CHECK CONSTRAINT [FK_tb_pedido_tb_hoja_ruta]
GO

/****** Object:  ForeignKey [FK_tb_hoja_ruta_tb_zona_reparto]    Script Date: 07/02/2013 23:53:32 ******/
ALTER TABLE [delivery].[tb_hoja_ruta]  WITH CHECK ADD  CONSTRAINT [FK_tb_hoja_ruta_tb_zona_reparto] FOREIGN KEY([idZonaReparto])
REFERENCES [delivery].[tb_zona_reparto] ([idZonaReparto])
GO
ALTER TABLE [delivery].[tb_hoja_ruta] CHECK CONSTRAINT [FK_tb_hoja_ruta_tb_zona_reparto]
GO

/****** Object:  ForeignKey [FK_tb_distrito_tb_provincia]    Script Date: 07/02/2013 23:53:32 ******/
ALTER TABLE [delivery].[tb_distrito]  WITH CHECK ADD  CONSTRAINT [FK_tb_distrito_tb_provincia] FOREIGN KEY([idProvincia])
REFERENCES [delivery].[tb_provincia] ([idProvincia])
GO
ALTER TABLE [delivery].[tb_distrito] CHECK CONSTRAINT [FK_tb_distrito_tb_provincia]
GO


/****** Object:  ForeignKey [FK_tb_distrito_tb_zona_reparto]    Script Date: 07/02/2013 23:53:32 ******/
ALTER TABLE [delivery].[tb_distrito]  WITH CHECK ADD  CONSTRAINT [FK_tb_distrito_tb_zona_reparto] FOREIGN KEY([idZonaReparto])
REFERENCES [delivery].[tb_zona_reparto] ([idZonaReparto])
GO
ALTER TABLE [delivery].[tb_distrito] CHECK CONSTRAINT [FK_tb_distrito_tb_zona_reparto]
GO

/****** Object:  ForeignKey [fk_tb_detalle_pedido_tb_pedido]    Script Date: 07/02/2013 23:53:32 ******/
ALTER TABLE [delivery].[tb_detalle_pedido]  WITH CHECK ADD  CONSTRAINT [fk_tb_detalle_pedido_tb_pedido] FOREIGN KEY([idPedido])
REFERENCES [delivery].[tb_pedido] ([idPedido])
GO
ALTER TABLE [delivery].[tb_detalle_pedido] CHECK CONSTRAINT [fk_tb_detalle_pedido_tb_pedido]
GO
/****** Object:  ForeignKey [fk_tb_detalle_pedido_tb_producto]    Script Date: 07/02/2013 23:53:32 ******/
ALTER TABLE [delivery].[tb_detalle_pedido]  WITH CHECK ADD  CONSTRAINT [fk_tb_detalle_pedido_tb_producto] FOREIGN KEY([idProducto])
REFERENCES [delivery].[tb_producto] ([idProducto])
GO
ALTER TABLE [delivery].[tb_detalle_pedido] CHECK CONSTRAINT [fk_tb_detalle_pedido_tb_producto]
GO
/****** Object:  ForeignKey [FK_tb_inspeccion_vehicular_tb_vehiculo]    Script Date: 07/02/2013 23:53:32 ******/
ALTER TABLE [delivery].[tb_inspeccion_vehicular]  WITH CHECK ADD  CONSTRAINT [FK_tb_inspeccion_vehicular_tb_vehiculo] FOREIGN KEY([idVehiculo])
REFERENCES [delivery].[tb_vehiculo] ([idVehiculo])
GO
ALTER TABLE [delivery].[tb_inspeccion_vehicular] CHECK CONSTRAINT [FK_tb_inspeccion_vehicular_tb_vehiculo]
GO

/****** Object:  ForeignKey [FK_tb_incidencia_tb_pedido]    Script Date: 07/02/2013 23:53:32 ******/
ALTER TABLE [delivery].[tb_incidencia]  WITH CHECK ADD  CONSTRAINT [FK_tb_incidencia_tb_pedido] FOREIGN KEY([idPedido])
REFERENCES [delivery].[tb_pedido] ([idPedido])
GO
ALTER TABLE [delivery].[tb_incidencia] CHECK CONSTRAINT [FK_tb_incidencia_tb_pedido]
GO

INSERT INTO delivery.tb_producto(descripcion, precioUnitario)VALUES('FAJITAS DE POLLO', 28.5);
INSERT INTO delivery.tb_producto(descripcion, precioUnitario)VALUES('CRISPY CHICKEN TACOS', 30.0);
INSERT INTO delivery.tb_producto(descripcion, precioUnitario)VALUES('CHEDAR OLD TIMER', 25.0);
INSERT INTO delivery.tb_producto(descripcion, precioUnitario)VALUES('CHICKEN FRIED CHICKEN', 18.0);
INSERT INTO delivery.tb_producto(descripcion, precioUnitario)VALUES('CAJUN PASTA', 25.5);
INSERT INTO delivery.tb_producto(descripcion, precioUnitario)VALUES('MARGARITA PRESIDENTE', 10.5);
INSERT INTO delivery.tb_producto(descripcion, precioUnitario)VALUES('TROPICAL SUNRISE MARGARITA', 13.5);
INSERT INTO delivery.tb_producto(descripcion, precioUnitario)VALUES('MARGARITAS TROPICALES', 15.0);

INSERT INTO delivery.tb_cliente(nombres, apellidoPaterno, apellidoMaterno,idTipoDocumentoIdentidad, numeroDocumentoIdentidad, direccion)
VALUES('CHRISTIAN', 'ARIAS', 'ORTIZ',1, '98094890', 'AV. LOS ANGELES 2590');
INSERT INTO delivery.tb_cliente(nombres, apellidoPaterno, apellidoMaterno,idTipoDocumentoIdentidad, numeroDocumentoIdentidad, direccion)
VALUES('ELIAS', 'GARCIA', 'GRAZ',1, '98094890', 'AV. LA MAR 321');

INSERT INTO delivery.tb_parametros(codigo,tipo,valor,descripcion)values(1,'MEDIO_PAGO','CREDITO','CREDITO');
INSERT INTO delivery.tb_parametros(codigo,tipo,valor,descripcion)values(2,'MEDIO_PAGO','CONTADO','CONTADO');

/* ADQUISICIONES */
CREATE TABLE [dbo].[tb_usuario](
	[idUsuario] [int] IDENTITY(1,1) NOT NULL,
	[codigo] [varchar](20) NULL,
	[contrasena] [varchar](200) NULL,
	[estado] [char](1) NULL,
	[Email_Usuario] [nvarchar](100) NULL,
	[Direccion_Usuario] [nvarchar](100) NULL,
	[Ciudad_Usuario] [nvarchar](100) NULL,
	[Telefono_Usuario] [nvarchar](100) NULL,
PRIMARY KEY CLUSTERED 
(
	[idUsuario] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_tipo_reclamo]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_tipo_reclamo](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[nombre] [varchar](100) NOT NULL,
	[cantidad_dias_atencion] [int] NOT NULL,
 CONSTRAINT [PK7] PRIMARY KEY NONCLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_solicitud_insumo]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_solicitud_insumo](
	[Numero_Solicitud] [int] IDENTITY(1,1) NOT NULL,
	[Tipo_Solicitud] [varchar](50) NULL,
	[Fecha_Solicitud] [datetime] NULL,
	[Fecha_Entrega] [datetime] NULL,
	[Descripcion] [varchar](100) NULL,
	[Estado_Solicitud] [tinyint] NULL,
	[Fecha_Creacion] [datetime] NULL,
	[Usuario_Creacion] [varchar](20) NULL,
	[Estado_Registro] [tinyint] NULL,
 CONSTRAINT [PK_SolicitudInsumo] PRIMARY KEY CLUSTERED 
(
	[Numero_Solicitud] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'1=Pendiente, 2=Atendida' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_solicitud_insumo', @level2type=N'COLUMN',@level2name=N'Estado_Solicitud'
GO
/****** Object:  Table [dbo].[tb_proyeccion_venta]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_proyeccion_venta](
	[Codigo_Insumo] [int] NULL,
	[Cantidad_Promedio] [decimal](18, 2) NULL,
	[Cantidad_Solicitada] [decimal](18, 2) NULL,
	[Cantidad_Sugerida] [decimal](18, 2) NULL,
	[Fecha_Creacion] [date] NULL,
	[Usuario_Creacion] [varchar](50) NULL,
	[Estado_Creacion] [tinyint] NULL,
	[Fecha_Inicio] [datetime] NULL,
	[Fecha_Fin] [datetime] NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_proveedor_insumo]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tb_proveedor_insumo](
	[Codigo_Proveedor] [int] NOT NULL,
	[Codigo_Insumo] [int] NOT NULL,
 CONSTRAINT [PK_ProveedorInsumo] PRIMARY KEY CLUSTERED 
(
	[Codigo_Proveedor] ASC,
	[Codigo_Insumo] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tb_proveedor]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_proveedor](
	[Codigo_Proveedor] [int] NOT NULL,
	[Razon_Social] [varchar](50) NULL,
	[RUC] [varchar](20) NULL,
	[Email_Proveedor] [nvarchar](100) NULL,
	[Direccion_Proveedor] [nvarchar](100) NULL,
	[Ciudad_Proveedor] [nvarchar](100) NULL,
	[Telefono_Proveedor] [nvarchar](100) NULL,
	[FormaPago_Proveedor] [nvarchar](100) NULL,
 CONSTRAINT [PK_Proveedor] PRIMARY KEY CLUSTERED 
(
	[Codigo_Proveedor] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_personal]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_personal](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[nombres] [varchar](100) NOT NULL,
	[apellidos] [varchar](100) NOT NULL,
	[es_administrador] [bit] NOT NULL,
	[usuario] [varchar](20) NOT NULL,
	[password] [varchar](20) NOT NULL,
 CONSTRAINT [PK3] PRIMARY KEY NONCLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_perfil]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_perfil](
	[idPerfil] [int] IDENTITY(1,1) NOT NULL,
	[codigo] [varchar](20) NULL,
	[nombre] [varchar](50) NULL,
	[descripcion] [varchar](200) NULL,
	[estado] [char](1) NULL,
PRIMARY KEY CLUSTERED 
(
	[idPerfil] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_orden_compra]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_orden_compra](
	[Numero_OC] [int] IDENTITY(1,1) NOT NULL,
	[Fecha_Generacion] [datetime] NULL,
	[Fecha_Entrega] [datetime] NULL,
	[Condicion_Pago] [int] NULL,
	[Motivo_Anulacion] [varchar](100) NULL,
	[subTotal] [decimal](18, 2) NULL,
	[igv] [decimal](18, 2) NULL,
	[total] [decimal](18, 2) NULL,
	[moneda] [char](3) NULL,
	[Estado_OC] [char](1) NULL,
	[Fecha_Creacion] [datetime] NULL,
	[Usuario_Registro] [varchar](20) NULL,
	[Estado_Registro] [tinyint] NULL,
 CONSTRAINT [PK_OrdenCompra] PRIMARY KEY CLUSTERED 
(
	[Numero_OC] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_insumo_stock]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tb_insumo_stock](
	[Codigo_Insumo] [int] NULL,
	[Stock_Maximo] [decimal](18, 2) NULL,
	[Stock_Minimo] [decimal](18, 2) NULL,
	[Stock_Actual] [decimal](18, 2) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tb_insumo]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_insumo](
	[Codigo_Insumo] [int] NOT NULL,
	[Descripcion_Insumo] [varchar](100) NULL,
	[Precio_Insumo] [decimal](18, 2) NULL,
 CONSTRAINT [PK_Insumo] PRIMARY KEY CLUSTERED 
(
	[Codigo_Insumo] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_estado_reclamo]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_estado_reclamo](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[nombre] [varchar](100) NOT NULL,
 CONSTRAINT [PK8] PRIMARY KEY NONCLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_empresa]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_empresa](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[nombre] [varchar](100) NOT NULL,
 CONSTRAINT [PK9] PRIMARY KEY NONCLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_documento_identidad]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_documento_identidad](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[nombre] [varchar](100) NOT NULL,
 CONSTRAINT [PK6] PRIMARY KEY NONCLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_detalle_solicitud_insumo]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tb_detalle_solicitud_insumo](
	[Numero_Item] [int] IDENTITY(1,1) NOT NULL,
	[Numero_Solicitud] [int] NULL,
	[Codigo_Insumo] [int] NULL,
	[Cantidad] [decimal](18, 2) NULL,
	[Estado_Registro] [int] NULL,
	[Numero_OC] [int] NULL,
	[Estado_DetalleSolicitud] [int] NULL,
 CONSTRAINT [PK_DetalleSolicitudInsumo] PRIMARY KEY CLUSTERED 
(
	[Numero_Item] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tb_detalle_orden_compra]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_detalle_orden_compra](
	[Numero_Item] [int] IDENTITY(1,1) NOT NULL,
	[Numero_OC] [int] NULL,
	[Codigo_Insumo] [int] NULL,
	[Precio] [decimal](18, 2) NULL,
	[Cantidad] [decimal](18, 2) NULL,
	[Estado_Detalle_OC] [tinyint] NULL,
	[Fecha_Creacion] [datetime] NULL,
	[Usuario_Registro] [varchar](20) NULL,
	[Estado_Registro] [tinyint] NULL,
 CONSTRAINT [PK_DetalleOrdenCompra] PRIMARY KEY CLUSTERED 
(
	[Numero_Item] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_cliente]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_cliente](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[nombres] [varchar](100) NOT NULL,
	[apellidos] [varchar](100) NOT NULL,
	[documento_identidad_tipo] [int] NOT NULL,
	[documento_identidad_numero] [varchar](25) NOT NULL,
	[telefono] [varchar](25) NOT NULL,
	[email] [varchar](25) NOT NULL,
	[direccion] [varchar](100) NOT NULL,
 CONSTRAINT [PK2] PRIMARY KEY NONCLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_punto_venta]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_punto_venta](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[empresa_id] [int] NOT NULL,
	[nombre] [varchar](100) NOT NULL,
	[direccion] [varchar](100) NOT NULL,
	[telefono] [varchar](25) NOT NULL,
	[usuario] [varchar](20) NOT NULL,
	[password] [varchar](20) NOT NULL,
 CONSTRAINT [PK1] PRIMARY KEY NONCLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[tb_reclamo]    Script Date: 07/04/2013 00:22:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tb_reclamo](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[analista_id] [int] NOT NULL,
	[cliente_id] [int] NOT NULL,
	[punto_venta_id] [int] NOT NULL,
	[tipo_id] [int] NOT NULL,
	[fecha_atencion_inicio] [date] NOT NULL,
	[fecha_atencion_final] [datetime] NOT NULL,
	[descripcion] [varchar](1000) NOT NULL,
	[estado_id] [int] NOT NULL,
	[porcentaje_avance] [int] NOT NULL,
	[solucion] [varchar](1000) NOT NULL,
	[administrador_id] [int] NOT NULL,
 CONSTRAINT [PK4] PRIMARY KEY NONCLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  ForeignKey [RefDocumento_Identidad102]    Script Date: 07/04/2013 00:22:58 ******/
ALTER TABLE [dbo].[tb_cliente]  WITH CHECK ADD  CONSTRAINT [RefDocumento_Identidad102] FOREIGN KEY([documento_identidad_tipo])
REFERENCES [dbo].[tb_documento_identidad] ([id])
GO
ALTER TABLE [dbo].[tb_cliente] CHECK CONSTRAINT [RefDocumento_Identidad102]
GO
/****** Object:  ForeignKey [RefEmpresa122]    Script Date: 07/04/2013 00:22:58 ******/
ALTER TABLE [dbo].[tb_punto_venta]  WITH CHECK ADD  CONSTRAINT [RefEmpresa122] FOREIGN KEY([empresa_id])
REFERENCES [dbo].[tb_empresa] ([id])
GO
ALTER TABLE [dbo].[tb_punto_venta] CHECK CONSTRAINT [RefEmpresa122]
GO
/****** Object:  ForeignKey [RefCliente62]    Script Date: 07/04/2013 00:22:58 ******/
ALTER TABLE [dbo].[tb_reclamo]  WITH CHECK ADD  CONSTRAINT [RefCliente62] FOREIGN KEY([cliente_id])
REFERENCES [dbo].[tb_cliente] ([id])
GO
ALTER TABLE [dbo].[tb_reclamo] CHECK CONSTRAINT [RefCliente62]
GO
/****** Object:  ForeignKey [RefEstado_Reclamo82]    Script Date: 07/04/2013 00:22:58 ******/
ALTER TABLE [dbo].[tb_reclamo]  WITH CHECK ADD  CONSTRAINT [RefEstado_Reclamo82] FOREIGN KEY([estado_id])
REFERENCES [dbo].[tb_estado_reclamo] ([id])
GO
ALTER TABLE [dbo].[tb_reclamo] CHECK CONSTRAINT [RefEstado_Reclamo82]
GO
/****** Object:  ForeignKey [RefPersonal132]    Script Date: 07/04/2013 00:22:58 ******/
ALTER TABLE [dbo].[tb_reclamo]  WITH CHECK ADD  CONSTRAINT [RefPersonal132] FOREIGN KEY([administrador_id])
REFERENCES [dbo].[tb_personal] ([id])
GO
ALTER TABLE [dbo].[tb_reclamo] CHECK CONSTRAINT [RefPersonal132]
GO
/****** Object:  ForeignKey [RefPersonal92]    Script Date: 07/04/2013 00:22:58 ******/
ALTER TABLE [dbo].[tb_reclamo]  WITH CHECK ADD  CONSTRAINT [RefPersonal92] FOREIGN KEY([analista_id])
REFERENCES [dbo].[tb_personal] ([id])
GO
ALTER TABLE [dbo].[tb_reclamo] CHECK CONSTRAINT [RefPersonal92]
GO
/****** Object:  ForeignKey [RefPunto_Venta112]    Script Date: 07/04/2013 00:22:58 ******/
ALTER TABLE [dbo].[tb_reclamo]  WITH CHECK ADD  CONSTRAINT [RefPunto_Venta112] FOREIGN KEY([punto_venta_id])
REFERENCES [dbo].[tb_punto_venta] ([id])
GO
ALTER TABLE [dbo].[tb_reclamo] CHECK CONSTRAINT [RefPunto_Venta112]
GO
/****** Object:  ForeignKey [RefTipo_Reclamo72]    Script Date: 07/04/2013 00:22:58 ******/
ALTER TABLE [dbo].[tb_reclamo]  WITH CHECK ADD  CONSTRAINT [RefTipo_Reclamo72] FOREIGN KEY([tipo_id])
REFERENCES [dbo].[tb_tipo_reclamo] ([id])
GO
ALTER TABLE [dbo].[tb_reclamo] CHECK CONSTRAINT [RefTipo_Reclamo72]
GO